package com.xyoto.community.controller;

import com.xyoto.community.dto.DeleteQuestionDTO;
import com.xyoto.community.dto.PageDTO;
import com.xyoto.community.dto.SaveQuestionDTO;
import com.xyoto.community.service.QuestionService;
import com.xyoto.community.utils.PageUtils;
import com.xyoto.community.utils.Result;
import com.xyoto.community.vo.QuestionListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * ClassName:   问答前台展示Web接口
 * Author:      挽风
 * Date:        2020
 * Copyright:   2020 by 挽风1.0版本
 * Description:
 **/


//@RestController
@RequestMapping("/topic")
@Api(value = "QuestionController", tags = "话题-问答前台接口（前台）")
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    /**
     * 新增问答
     *
     * @param saveQuestionDTO 问答表单Dto
     *
     * @return 操作状态
     */
    @ApiOperation(value = "新增问答Web接口", notes = "新增问答Web接口", httpMethod = "POST")
    @PostMapping("/saveQuestion")
    public Result saveQuestion(@Valid @RequestBody SaveQuestionDTO saveQuestionDTO){
        return questionService.saveQuestion(saveQuestionDTO);
    }

    /**
     * 根据问答id查询问答详情
     *
     * @param questionId 问答id
     *
     * @return 问答详情
     */
    @ApiOperation(value = "根据问答id查询问答详情Web接口", notes = "根据问答id查询问答详情Web接口", httpMethod = "GET")
    @GetMapping("/getQuestion")
    public Result getQuestionDetailsById(@RequestParam(value = "questionId", name = "questionId") Integer questionId){
        return questionService.getQuestionDetailsById(questionId);
    }

    @ApiOperation(value = "获取问答列表时间排序通过话题id", notes = "获取问答列表时间排序通过话题id", httpMethod = "GET")
    @ApiImplicitParam(name = "topicId",value = "话题id" ,required = true)
    @GetMapping("/getQuestionListByTime")
    public Result<PageUtils<QuestionListVo>> getQuestionList(PageDTO pageDTO, Integer topicId){
        return questionService.getQuestionListByTime(pageDTO,topicId);
    }

    @ApiOperation("删除问答")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "questionId" ,value = "删除问答" ,required = true)
    })
    @DeleteMapping("/removeQuestionById")
    public Result removeQuestion(@RequestBody DeleteQuestionDTO deleteQuestionDTO){
        return questionService.removeQuestion(deleteQuestionDTO.getQuestionId());
    }

}
